import {api} from './libs/api.js';
let _self;
export const index =  {
	data() {
		return {
			optLock:false,
			salerShow:false,
			popupShow:false,
			salerInfo:{},
			customerData:{},
			selectList:{
				"shop_id":{"item":[],"index":0,"key":"cStroreId","data":"","name":"门店","form_keys":{"shop_id":"cStroreId","shop_name":"cStoreName"}},
			},
			formData:{},
			customerInfo:{}
		}
	},
	
	watch:{
		salerInfo(val){
			if(val.user_code){
				this.customerData={"user_code":val.user_code};
			}	
		},

	},
	
	mounted() {
		_self = this;
	},
	onReachBottom:function(e){
	},
	onLoad:function(option) {
	},
	
	methods: {
		async initData(){
			this.selectList["shop_id"]["item"]=await api.getShopList({});
			this.initSelect();
			console.log(this.member);
			this.salerInfo=this.member;
			
		},
		
		selectChange: function(e) {
			let key=e.currentTarget.dataset["key"];
		    this.selectList[key]["index"] = e.detail.value;			
			this.initSelect()
		
		},
		
		initSelect(){
			for(let key in this.selectList){
				if(this.selectList[key]["form_keys"]){
					for(let k1 in this.selectList[key]["form_keys"]){
						let item_k1=this.selectList[key]["form_keys"][k1];
						this.formData[k1]=this.selectList[key]["item"][this.selectList[key]["index"]][item_k1];
					}
				}
			}

			console.log(this.formData);
		},
		
		
		submitForm: function(e) {
			this.formData["customer"]=this.customerInfo;
			delete this.salerInfo["data1"];
			this.formData["saler"]=this.salerInfo;
			
			let ret=api.setUserData({"data1":this.formData});

			uni.showToast({icon:"none",title:"提交成功！"});
			setTimeout(function(){uni.switchTab({url: "/pages/product/index"});},2000);　　
			
			
		},
		
		showCode:function(){
			this.customerInfo={};
		}
			
		
				
	},
}